<?php

namespace App\Http\Controllers\Mp;

use App\Http\Resources\Mp\BookRuleResource;
use App\Models\BookRule;
use App\Models\SchoolRule;
use Illuminate\Http\Request;

/**
 * Class AdditionOrderController
 * @package App\Http\Controllers\Mp
 * @author zjw
 */
class AdditionRuleController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     *
     */
    public function index(Request $request)
    {
        $date = $request->get('date');
        $rules = BookRule::eatDateIs($date)->schoolIs(\Auth::user()->school_id)->get();
        if ((int)$request->is_limit === SchoolRule::IS_LIMIT) {
            $rules = $rules->filter(function ($v) {
                return $v->is_active;
            });
        }
        return BookRuleResource::collection($rules);
    }
}
